package com.wenjiang.config.handler;

import com.wenjiang.common.exception.*;
import com.wenjiang.common.lang.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(TokenException.class)
    public Object TokenException(HttpServletResponse response){
        return Result.fail(401,"token已失效请重新登录");
    }

    @ExceptionHandler(SystemException.class)
    public Object SystemException(HttpServletResponse response){
        return Result.fail(500,"系统异常");
    }

    @ExceptionHandler(SystemBusyException.class)
    public Object SystemBusyException(HttpServletResponse response){
        return Result.fail(500,"系统繁忙，请稍后重试");
    }

    @ExceptionHandler(FileException.class)
    public  Object FileException(){
        return Result.fail("文件处理错误");
    }

    @ExceptionHandler(SearchException.class)
    public  Object  SearchException()
    {
        return Result.fail("搜索服务器异常","轻一点对待");
    }
}
